import { BrowserWindow } from 'electron'

export const channelList = [
  {
    // 设置托盘区菜单
    channel: 'setMenu',
    callback: 'setMenu',
    setMenu: (mainWin, { data }) => {
      mainWin.setSize(data.width, data.height)
    }
  },
  {
    // 修改窗口大小
    channel: 'windowResize',
    callback: 'resizeWindow',
    resizeWindow: (mainWin, { data }) => {
      mainWin.setSize(data.width, data.height)
    }
  },
  {
    // 设置窗口置顶
    channel: 'setWinTop',
    callback: 'setWinTop',
    setWinTop: (mainWin, { e, data }) => {
      const win = BrowserWindow.fromWebContents(e.sender)
      win.setAlwaysOnTop(data, 'screen-saver')
    }
  },
  {
    // 缩小窗口到任务栏
    channel: 'minimize',
    callback: 'setMinimize',
    setMinimize: (mainWin, { e }) => {
      const win = BrowserWindow.fromWebContents(e.sender)
      win.minimize()
    }
  },
  {
    // 窗口放大全屏
    channel: 'maximize',
    callback: 'setMaximize',
    setMaximize: (mainWin, { e }) => {
      const win = BrowserWindow.fromWebContents(e.sender)
      win.maximize()
    }
  },
  {
    // 取消窗口全屏
    channel: 'unmaximize',
    callback: 'setUnmaximize',
    setUnmaximize: (mainWin, { e }) => {
      const win = BrowserWindow.fromWebContents(e.sender)
      win.unmaximize()
    }
  },
  {
    // 关闭窗口
    channel: 'closeWin',
    callback: 'closeWin',
    closeWin: (mainWin, { e, data }) => {
      const win = BrowserWindow.fromWebContents(e.sender)
      if (data === 0) {
        // 关闭窗口
        win.close()
      } else if (data === 1) {
        // 关闭窗口到托盘区
        win.setSkipTaskbar(true)
        win.hide()
      }
    }
  }
]
